#include <iostream>
#include <numeric>
#include "chain.h"

using namespace std;

int main()
{
    chain<int> y;
    y.push_back(2);
    y.push_back(6);
    y.push_back(1);
    y.push_back(4);
    y.push_back(9);
    y.push_back(10);
   
    cout << "Inserted 6 integers, list y should be 1 2 3 4 5 6" << endl;
    cout << "Size of y = " << y.size() << endl;

       // test iterator
   cout << "Ouput using forward iterators pre and post ++" << endl;
   for (chain<int>::iterator it = y.begin();
        it != y.end(); it++)
      cout << *it << "  ";
   cout << endl;
   
   y.remove(10);
   y.pop_back();
   chain<int> z(y);
   cout << "copy chain z : " << z << endl;

   cout << "Ouput using forward iterators post ++ and remove item" << endl;
   for (chain<int>::iterator iter = y.begin();
        iter != y.end(); ++iter)
   {
      cout << *iter << "  ";
      *iter += 1;
   }
   cout << endl;
  
   y.merge(z);
   cout << endl;
   cout << "z merge by y list is " << y << endl;
   cout << "after merge z : " << z << endl;

   cout << y.size();
   // try out an STL algorithm
   int sum = accumulate(y.begin(), y.end(), 0);
   cout << "The sum of the elements is " << sum << endl;
   
   y.clear();
   cout << "clear all items " << endl;
   cout << y << endl;

   return 0;
}